package com.ruoyi.web.tdmdata.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.tdmdata.domain.TdmZhongYaoFangJi;
import com.ruoyi.web.tdmdata.service.ITdmZhongYaoFangJiService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 中药方剂Controller
 * 
 * @author ly
 * @date 2022-03-14
 */
@RestController
@RequestMapping("/tdmdata/TdmZhongYaoFangJi")
public class TdmZhongYaoFangJiController extends BaseController
{
    @Autowired
    private ITdmZhongYaoFangJiService tdmZhongYaoFangJiService;

    /**
     * 查询中药方剂列表
     */
    // @PreAuthorize("@ss.hasPermi('tdmdata:TdmZhongYaoFangJi:list')")
    @GetMapping("/list")
    public TableDataInfo list(TdmZhongYaoFangJi tdmZhongYaoFangJi)
    {
        startPage();
        List<TdmZhongYaoFangJi> list = tdmZhongYaoFangJiService.selectTdmZhongYaoFangJiList(tdmZhongYaoFangJi);
        return getDataTable(list);
    }

    /**
     * 导出中药方剂列表
     */
    //@PreAuthorize("@ss.hasPermi('tdmdata:TdmZhongYaoFangJi:export')")
    @Log(title = "中药方剂", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TdmZhongYaoFangJi tdmZhongYaoFangJi)
    {
        List<TdmZhongYaoFangJi> list = tdmZhongYaoFangJiService.selectTdmZhongYaoFangJiList(tdmZhongYaoFangJi);
        ExcelUtil<TdmZhongYaoFangJi> util = new ExcelUtil<TdmZhongYaoFangJi>(TdmZhongYaoFangJi.class);
        util.exportExcel(response, list, "中药方剂数据");
    }

    /**
     * 获取中药方剂详细信息
     */
    //@PreAuthorize("@ss.hasPermi('tdmdata:TdmZhongYaoFangJi:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tdmZhongYaoFangJiService.selectTdmZhongYaoFangJiById(id));
    }

    /**
     * 新增中药方剂
     */
    // @PreAuthorize("@ss.hasPermi('tdmdata:TdmZhongYaoFangJi:add')")
    @Log(title = "中药方剂", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TdmZhongYaoFangJi tdmZhongYaoFangJi)
    {
        return toAjax(tdmZhongYaoFangJiService.insertTdmZhongYaoFangJi(tdmZhongYaoFangJi));
    }

    /**
     * 修改中药方剂
     */
    // @PreAuthorize("@ss.hasPermi('tdmdata:TdmZhongYaoFangJi:edit')")
    @Log(title = "中药方剂", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TdmZhongYaoFangJi tdmZhongYaoFangJi)
    {
        return toAjax(tdmZhongYaoFangJiService.updateTdmZhongYaoFangJi(tdmZhongYaoFangJi));
    }

    /**
     * 删除中药方剂
     */
    //@PreAuthorize("@ss.hasPermi('tdmdata:TdmZhongYaoFangJi:remove')")
    @Log(title = "中药方剂", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tdmZhongYaoFangJiService.deleteTdmZhongYaoFangJiByIds(ids));
    }
}
